<template>
  <div>
    <t-tabs v-if="site_tag === 'jtt'" @change="(val)=>{queryParams.projectCategory=val;getList();}" v-model="queryParams.projectCategory" style="margin-bottom: 10px">
      <t-tab-panel :key="item.id" :value="item.id" v-for="(item) in [{'name': '全部',id: null},...projectCategoryOptions]" :label="item.name" :destroyOnHide="false">
      </t-tab-panel>
    </t-tabs>
    <t-table
      rowKey="index"
      size="small"
      :data="data"
      :columns="site_tag === 'jtt'?columns:columns.filter(val=>{ return  val.title!=='计划类别'})"
      hover
      :pagination="pagination"
      :loading="dataLoading"
      :sort="sort"
      :hideSortTips="true"
      @sort-change="sortChange"
    >
      <template #projectNum="{ row }">
        <div v-if="row.projectNum">
          {{row.projectNum}}
        </div>
        <div v-else>
          暂未分配
        </div>
      </template>
      <template #projectName="{ row }">
<!--        <t-link @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_detail=true" hover="color" theme="primary">{{row.projectName}}</t-link>-->
        {{row.projectName}}
      </template>
      <template #subjectClassification="{ row }">
        {{ row.subjectClassification | filterByDict(dict.type.subject_classification) }}
      </template>
      <template #projectType="{ row }">
        {{ row.projectType | filterByDict(dict.type.project_type) }}
      </template>
      <template #adviceFunding="{row}">
        {{row.adviceFunding}}万元
      </template>
      <template #subsidyFunding="{row}">
        {{row.subsidyFunding}}万元
      </template>
<!--      <template #op="{ row }">-->
<!--        &lt;!&ndash;        <t-button  v-if="row.id.toString().includes('202202')" @click="allApply(row)" size="small" variant="text"&ndash;&gt;-->
<!--        &lt;!&ndash;                   class="t-button-link">&ndash;&gt;-->
<!--        &lt;!&ndash;          <t-icon name="edit-1" slot="icon"/>&ndash;&gt;-->
<!--        &lt;!&ndash;          项目数据完善&ndash;&gt;-->
<!--        &lt;!&ndash;        </t-button>&ndash;&gt;-->
<!--        <t-button size="small" @click="dialog.objId=row.id;dialog.header=row.projectName;dialog.open_project_detail=true" variant="text" class="t-button-link">-->
<!--          <t-icon name="info-circle" slot="icon"/>-->
<!--          详情-->
<!--        </t-button>-->
<!--        &lt;!&ndash;        <t-button @click="createPDF(row)" size="small"&ndash;&gt;-->
<!--        &lt;!&ndash;                  variant="text" class="t-button-link">&ndash;&gt;-->
<!--        &lt;!&ndash;          <t-icon name="file-pdf" slot="icon"/>&ndash;&gt;-->
<!--        &lt;!&ndash;          导出PDF&ndash;&gt;-->
<!--        &lt;!&ndash;        </t-button>&ndash;&gt;-->
<!--        &lt;!&ndash;        <t-button @click="dialog.header='审批记录';dialog.objId=row.id;dialog.open_approve_list=true" size="small" variant="text" class="t-button-link">&ndash;&gt;-->
<!--        &lt;!&ndash;          <t-icon name="info-circle" slot="icon"/>&ndash;&gt;-->
<!--        &lt;!&ndash;          审批记录&ndash;&gt;-->
<!--        &lt;!&ndash;        </t-button>&ndash;&gt;-->
<!--      </template>-->
      <template #dateRange="{ row }">
        {{ row.startDate }}-{{ row.endDate }}
      </template>
<!--      <template #projectStatus="{ row }">-->
<!--        <t-tag  @click="dialog.header=row.projectName;dialog.objId=row.id;dialog.open_approve_list=true" class="cursor-pointer" :theme="handleTheme(row.projectStatus, dict.type.project_status)" variant="light">-->
<!--          {{ row.projectStatus | filterByDict(dict.type.project_status) }}-->
<!--        </t-tag>-->
<!--      </template>-->
    </t-table>
    <project-detail-dialog  tabDefaultValue="1"  :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_project_detail" v-if="dialog.open_project_detail"></project-detail-dialog>
    <approve-list :header="dialog.header" :objId="dialog.objId" :visible.sync="dialog.open_approve_list" v-if="dialog.open_approve_list"></approve-list>
  </div>
</template>

<script>
// import projectDetailDialog from "../../../kjxm/pm/components/project-detail-dialog.vue";
import approveList from "../../../kjxm/approve/components/approve-list.vue";

export default {
  name: "kjxm-list",
  dicts:["project_type", "subject_classification", "sys_user_sex", "prof_tit", "degree", "duty", "platform_type", "member_type", "project_status"],
  components:{
    // projectDetailDialog,
    projectDetailDialog: () => import('../../../kjxm/pm/components/project-detail-dialog.vue'),
    approveList
  },
  props:["deptId", "idCard"],
  data(){
    return {
      site_tag: import.meta.env.VITE_SITE_TAG,
      deptMenuOptions: [],
      sort:[],
      dialog:{
        open_project_detail: false,
        header: "",
        objId: 0,
        open_approve_list: false
      },
      dictTypes: {},
      projectCategoryOptions:[],
      columns:[
        // {
        //   colKey: "id",
        //   title: "项目编号",
        //   align: "center",
        //   ellipsis: true
        // },
        // {
        //   colKey: "declareDate",
        //   title: "申报年度",
        //   align: "center"
        // },
        {
          colKey: "projectNum",
          title: "项目编号",
          align: "center",
          width: 120,
          sorter: true,
          // ellipsis: true,
        },
        {
          colKey: "projectName",
          title: "项目名称",
          align: "center",
          // ellipsis: true,
          width: 220

        },
        {
          colKey: "adviceFunding",
          title: "建议经费总概算",
          align: "center",
          width: 160,
          sorter: true,
        },
        {
          colKey: "subsidyFunding",
          title: import.meta.env.VITE_SITE_TAG==='jtt'?"厅拨经费":`集团补助经费`,
          align: "center",
          sorter: true,
          width: 140,
        },
        {
          colKey: "startDate",
          title: "开始时间",
          align: "center",
          sorter: true,
          width: 120,
        },
        {
          colKey: "endDate",
          title: "结束时间",
          align: "center",
          sorter: true,
          width: 120,
        },
        {
          colKey: "projectLeaderName",
          title: "项目负责人",
          align: "center",
          width: 100
        },
        {
          colKey: "nickName",
          title: "填报人",
          align: "center",
          width: 100
        },
        {
          colKey: "declareDeptName",
          title: "承担单位",
          align: "center",
          width: 180,
          sorter: true
        },
        {
          colKey: "projectCategoryName",
          title: "计划类别",
          align: "center",
          width: 120
        },
        {
          colKey: "subjectClassification",
          title: "学科分类",
          align: "center",
          width: 100
        },
        {
          colKey: "projectType",
          title: "项目类型",
          align: "center",
          width: 120
        },
        {
          colKey: "declareDate",
          title: "申报日期",
          align: "center",
          // ellipsis: true,
          width: 110,
          sorter: true,
        },
        // {
        //   colKey: "attributeDeptName",
        //   title: "归口管理单位",
        //   align: "center"
        // },
        // {
        //   colKey: "projectStatus",
        //   title: "项目状态",
        //   align: "center",
        //   width:220,
        //   fixed: 'right',
        //   sorter: true
        // },
        // {
        //   colKey: "op",
        //   title: "操作",
        //   align: "center",
        //   width: 120,
        //   fixed: 'right'
        // },
      ],
      data:[],
      dataLoading: false,
      queryParams: {
        declareYear: '',
        projectDateRange: [],
        declareDateRange: [],
        declareDate: '',
        startDate: '',
        endDate: '',
        startDeclareDate: '',
        endDeclareDate: '',
        startAdviceFunding: null,
        endAdviceFunding: null,
        startSubsidyFunding: '',
        endSubsidyFunding: '',
        multilevelDeptId: null,
        projectLeaderName: '',
        projectMemberName: '',
        pageNum: 1,
        pageSize: 10,
        projectCategory: null,
        projectName: '',
        projectType: '',
        projectNum: '',
        projectStatus: '',
        subjectClassification: '',
        sortGroup: '',
        deptName: '',
        declareDeptName: '',
        projectStatuss: [],
        deptId: this.deptId,
        idCard: this.idCard,
      },
      pagination: {
        current: 1,
        pageSize: 10,
        total: 0,
        showPageSize: true,
        pageSizeOptions: [10,20,30],
        showFirstAndLastPageBtn: false,
        onChange: (pageInfo) => {
          Object.assign(this.pagination,pageInfo)
          this.queryParams.pageNum = pageInfo.current || 1;
          this.queryParams.pageSize = pageInfo.pageSize;
          this.getList()
        },
      }
    }
  },
  created() {
    this.getList();
    this.getDeclareTree();
  },
  methods:{
    getList(){
      if(this.deptId){
        this.dataLoading = true;
        this.$api.kjxm.project.list(this.queryParams).then(response=>{
          this.pagination.total = response.total;
          this.data = response.rows;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
      }else if(this.idCard){
        this.dataLoading = true;
        this.$api.kjxm.project.myJoinList(this.queryParams).then(response=>{
          this.pagination.total = response.total;
          this.data = response.rows;
          this.dataLoading = false;
        }).catch((e) => {
          this.dataLoading = false;
          this.$message.error(e.toString());
        });
      }

    },
    sortChange(sort){
      this.sort = sort;
      let orderByColumn = []
      let isAsc = []
      if(sort instanceof Array){
        orderByColumn = sort.map(val=>val.sortBy)
        isAsc = sort.map(val=>val.descending?`desc`:`asc`)
      }else {
        orderByColumn = [sort.sortBy]
        isAsc = [sort.descending?`desc`:`asc`]
      }
      this.queryParams.orderByColumn = orderByColumn.join(",")
      this.queryParams.isAsc = isAsc.join(",")
      this.getList();
    },
    getDeclareTree() {
      this.$api.kjxm.project.planCategoryList().then(response => {
        this.projectCategoryOptions = this.handleTree(response.data, "id");
      }).catch((e) => {
        this.$message.error(e.toString());
      });
    },
  }
}
</script>

<style scoped>

</style>
